﻿using System;
using System.Data;
using System.Collections.Generic;
using OnlineTestCOMMON;
using OnlineTestDAL;
using OnlineTestModel;

namespace OnlineTestBLL
{
	/// <summary>
	/// questions
	/// </summary>
	public partial class QuestionsBLL
	{
		private readonly QuestionsDAL dal = new QuestionsDAL();

		public QuestionsBLL()
		{
		}

		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			return dal.Exists(id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Questions model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Questions model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 更新试题的时候，将前一题设为禁用
		/// </summary>
		public bool UpdateStatus(int status, int questionId)
		{
			return dal.UpdateStatus(status, questionId);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{

			return dal.Delete(id);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist)
		{
			return dal.DeleteList(idlist);
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Questions GetModel(int id)
		{

			return dal.GetModel(id);
		}



		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top, string strWhere, string filedOrder)
		{
			return dal.GetList(Top, strWhere, filedOrder);
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Questions> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Questions> DataTableToList(DataTable dt)
		{
			List<Questions> modelList = new List<Questions>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Questions model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Questions();
					if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
					{
						model.Id = int.Parse(dt.Rows[n]["id"].ToString());
					}
					if (dt.Rows[n]["questionname"] != null && dt.Rows[n]["questionname"].ToString() != "")
					{
						model.QuestionName = dt.Rows[n]["questionname"].ToString();
					}
					if (dt.Rows[n]["versionnumber"] != null && dt.Rows[n]["versionnumber"].ToString() != "")
					{
						model.VersionNumber = int.Parse(dt.Rows[n]["versionnumber"].ToString());
					}
					if (dt.Rows[n]["predifficult"] != null && dt.Rows[n]["predifficult"].ToString() != "")
					{
						model.PreDifficult = dt.Rows[n]["predifficult"].ToString();
					}

					if (dt.Rows[n]["chapter"] != null && dt.Rows[n]["chapter"].ToString() != "")
					{
						model.Chapter = dt.Rows[n]["chapter"].ToString();
					}
					if (dt.Rows[n]["part"] != null && dt.Rows[n]["part"].ToString() != "")
					{
						model.Part = dt.Rows[n]["part"].ToString();
					}
					if (dt.Rows[n]["questiontypeid"] != null && dt.Rows[n]["questiontypeid"].ToString() != "")
					{
						model.QuestionTypeId = int.Parse(dt.Rows[n]["questiontypeid"].ToString());
					}
					if (dt.Rows[n]["blankline"] != null && dt.Rows[n]["blankline"].ToString() != "")
					{
						model.BlankLine = int.Parse(dt.Rows[n]["blankline"].ToString());
					}
					if (dt.Rows[n]["correctanswer"] != null && dt.Rows[n]["correctanswer"].ToString() != "")
					{
						model.CorrectAnswer = dt.Rows[n]["correctanswer"].ToString();
					}
                    if (dt.Rows[n]["correctcount"] != null && dt.Rows[n]["correctcount"].ToString() != "")
                    {
                        model.ParentId = int.Parse(dt.Rows[n]["correctcount"].ToString());
                    }
                    if (dt.Rows[n]["totalcount"] != null && dt.Rows[n]["totalcount"].ToString() != "")
                    {
                        model.ParentId = int.Parse(dt.Rows[n]["totalcount"].ToString());
                    }
					if (dt.Rows[n]["parentid"] != null && dt.Rows[n]["parentid"].ToString() != "")
					{
						model.ParentId = int.Parse(dt.Rows[n]["parentid"].ToString());
					}
					if (dt.Rows[n]["truedifficult"] != null && dt.Rows[n]["truedifficult"].ToString() != "")
					{
						model.TrueDifficult = dt.Rows[n]["truedifficult"].ToString();
					}
					if (dt.Rows[n]["partitiondegree"] != null && dt.Rows[n]["partitiondegree"].ToString() != "")
					{
						model.PartitionDegree = dt.Rows[n]["partitiondegree"].ToString();
					}
					if (dt.Rows[n]["courseid"] != null && dt.Rows[n]["courseid"].ToString() != "")
					{
						model.CourseId = int.Parse(dt.Rows[n]["courseid"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
		//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method

		#region

		/// <summary>
		/// 得到QuestionEx实体列表
		/// </summary>
		public List<QuestionEx> GetQuestionExList(int courseid)
		{
			return dal.GetQuestionExList(courseid);
		}

		#endregion

		/// <summary>
		/// 获得某试卷的数据列表
		/// </summary>
		public List<PaperQuestionEx> GetListByPaperId(string strWhere)
		{
			return dal.GetListByPaperId(strWhere);
		}
	}
}

